package org.light.shiroauth;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.IncorrectCredentialsException;
import org.apache.shiro.authc.UnknownAccountException;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.crypto.SecureRandomNumberGenerator;
import org.apache.shiro.crypto.hash.Sha1Hash;
import org.apache.shiro.subject.Subject;

/**
*用户注册与登录时用到的函数
*/
public class UserRegisteAndLogin
{
	/**
	* 用户注册时加密用户的密码
	* 输入密码明文 返回密文与盐值
	* @param password
	* @return 第一个是密文  第二个是盐值
	*/
	public static String[] encryptPassword(String password)
	{
		String salt = new SecureRandomNumberGenerator().nextBytes().toHex(); //生成盐值
		String ciphertext = new Sha1Hash(password,salt,3).toString(); //生成的密文

		String[] strings = new String[]{salt, ciphertext};

		return strings;
	}

	/**
	* 获得本次输入的密码的密文
	* @param password
	* @param salt
	* @return
	*/
	public static String getInputPasswordCiph(String password, String salt)
	{
		if(salt == null)
		{
			password = "";
		}

		String ciphertext = new Sha1Hash(password,salt,3).toString(); //生成的密文

		return ciphertext;
	}

}
